#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
// write your code here......
#include <vector>
using namespace std;

int main()
{

    // write your code here......
    vector<int> arr;
    for (int i = 0; i < 5; i++)
    {
        int temp = 0;
        cin >> temp;
        arr.push_back(temp);
    }
    vector<int>::iterator it;
    for (it = arr.begin(); it != arr.end(); it++)
    {
        cout << *it << ' ';
    }
    cout << endl;

    vector<int>::reverse_iterator rit;
    for (rit = arr.rbegin(); rit != arr.rend(); rit++)
    {
        cout << *rit << ' ';
    }

    return 0;
}

#include <iostream>
// write your code here......
#include <vector>
using namespace std;

int main()
{

    // write your code here......
    vector<int> arr;
    for (int i = 0; i < 5; i++)
    {
        int temp = 0;
        cin >> temp;
        arr.push_back(temp);
    }
    vector<int>::iterator it;
    for (it = arr.begin(); it != arr.end(); it++)
    {
        cout << *it << ' ';
    }
    cout << endl;

    vector<int>::reverse_iterator rit;
    for (rit = arr.rbegin(); rit != arr.rend(); rit++)
    {
        cout << *rit << ' ';
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    vector<int>a;
    // write your code here......
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        int temp = 0;
        cin >> temp;
        a.push_back(temp);
    }
    auto it = a.rbegin();
    for (int i = 0; i < k; i++)
    {
        printf("%d ", *it);
        it++;
        a.pop_back();
    }
    return 0;
}
